package com.serverapk.camera;

import org.json.JSONObject;

import com.serverapk.util.ToolsUtil;

/**
 * 获取IP摄像头协议，获取摄像头照片前先发送协议
 * "===98$$${\"msg\":\"c2d.start_living\",\"t_s\":1524106297,\"k\":\"ab54818443560435158026449601d635\",\"cid\":0,\"sid\":0}"
 * 
 * @author Administrator
 *
 */
public class JsonHandle {
	String id = "admin";
	String id_key = "88888888";
	String dev_key = "TMFj$I5ibVP#TuUX";
	String msg = "c2d.start_living";
	int t_s = 0;
	String key = "";
	int cid = 0;
	int sid = 0;

	public String getKey(int utc) {
		String str = "";
		str += id;
		str += "|";
		str += id_key;
		str += "|";
		str += String.valueOf(utc);
		str += "|";
		str += dev_key;
		str += "|";
		str += String.valueOf(cid);
		str += "|";
		str += String.valueOf(sid);
		return str;
	}

	public JSONObject createJSONWithJSONObject() {
		try {
			JSONObject jsonObject = new JSONObject();
			int utc = ToolsUtil.getUTC();
			jsonObject.put("msg", msg);
			jsonObject.put("t_s", utc);
			jsonObject.put("k", ToolsUtil.md5(getKey(utc)));
			jsonObject.put("cid", cid);
			jsonObject.put("sid", sid);
			return jsonObject;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	public String getJsonMsg() {
		String str = "";
		JSONObject json = createJSONWithJSONObject();
		if (json != null) {
			str += "===";
			str += json.toString().length();
			str += "$$$";
			str += json;
		}
		return str;
	}
}
